/**
 * 
 */
package chess;

import static org.junit.Assert.*;

import java.util.ArrayList;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

import chess.client.Constants;

/**
 * @author Daniel Silion
 *
 */
public class JUConstants {

	private ArrayList<Integer[]> bExpectedPieceMoves;
	
	/**
	 * @throws java.lang.Exception
	 */
	@BeforeClass
	public static void setUpBeforeClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@AfterClass
	public static void tearDownAfterClass() throws Exception {
	}

	/**
	 * @throws java.lang.Exception
	 */
	@Before
	public void setUp() throws Exception {
		bExpectedPieceMoves = new ArrayList<Integer[]>();
	}

	/**
	 * @throws java.lang.Exception
	 */
	@After
	public void tearDown() throws Exception {
		bExpectedPieceMoves.clear();
	}

	/**
	 * Test method for {@link chess.client.Constants#isLegalMove(java.lang.String, java.lang.Integer, java.lang.Integer)}.
	 */
	@Test
	public final void testIsLegalMoveBishopC1() {
		//Test Legallity of Bishop @ c1 move to a3
			assertTrue("\n===================   Test Legallity of Bishop @ c1 move to a3.   ===================\n", Constants.isLegalMove("wb", 2, -2, 0, 2));
	}
	
	@Test
	public final void testIsLegalMovePawnD7() {
		//Test Legallity of Pawn @ d7 move to d6
			assertTrue("\n===================   Test Legallity of Pawn @ d7 move to d6.   ===================\n", Constants.isLegalMove("bp", -1, 0, 6, 3));
		
		//Test Legallity of Pawn @ d7 move to d5
			assertTrue("\n===================   Test Legallity of Pawn @ d7 move to d5.   ===================\n", Constants.isLegalMove("bp", -2, 0, 6, 3));
		
		//Test Legallity of Pawn @ d7 move to c6
			assertTrue("\n===================   Test Legallity of Pawn @ d7 move to c6.   ===================\n", Constants.isLegalMove("bp", -1, -1, 6, 3, "wp"));
			
		//Test Legallity of Pawn @ d7 move to e6
			assertFalse("\n===================   Test Legallity of Pawn @ d7 move to e6.   ===================\n", Constants.isLegalMove("bp", -1, 1, 6, 3));
	}

	/**
	 * Test methods for {@link chess.client.Constants#getAllPieceMoves(java.lang.String, java.lang.Integer, java.lang.Integer)}.
	 */
	@Test
	//Test the Rook @ c3 moves
	public final void testGetAllPieceMovesRookC3() {
		ArrayList<Integer[]> bActualPieceMoves;
	
		//Prepare Expected
			bExpectedPieceMoves.add(new Integer[] {2, 2, 2, 0});
			bExpectedPieceMoves.add(new Integer[] {2, 2, 0, 2});
			
			bExpectedPieceMoves.add(new Integer[] {2, 2, 2, 1});
			bExpectedPieceMoves.add(new Integer[] {2, 2, 1, 2});
			
			bExpectedPieceMoves.add(new Integer[] {2, 2, 2, 3});
			bExpectedPieceMoves.add(new Integer[] {2, 2, 3, 2});
			
			bExpectedPieceMoves.add(new Integer[] {2, 2, 2, 4});
			bExpectedPieceMoves.add(new Integer[] {2, 2, 4, 2});
			
			bExpectedPieceMoves.add(new Integer[] {2, 2, 2, 5});
			bExpectedPieceMoves.add(new Integer[] {2, 2, 5, 2});
			
			bExpectedPieceMoves.add(new Integer[] {2, 2, 2, 6});
			bExpectedPieceMoves.add(new Integer[] {2, 2, 6, 2});
			
			bExpectedPieceMoves.add(new Integer[] {2, 2, 2, 7});
			bExpectedPieceMoves.add(new Integer[] {2, 2, 7, 2});
			
		//Get Actual
			bActualPieceMoves = Constants.getAllPieceMoves("wr", 2, 2);
		
		//Assert Equal
			MyAsserts.assertArrayArrayListEquals("\n===================   Test the Bishop @ c3 moves.   ===================\n", bExpectedPieceMoves, bActualPieceMoves);
	}
	
	@Test
	//Test the Knight @ d2 moves
	public final void testGetAllPieceMovesKnightD2() {
		ArrayList<Integer[]> bActualPieceMoves;
	
		//Prepare Expected
			bExpectedPieceMoves.add(new Integer[] {1, 3, 0, 1});
			bExpectedPieceMoves.add(new Integer[] {1, 3, 2, 1});
			bExpectedPieceMoves.add(new Integer[] {1, 3, 3, 2});
			bExpectedPieceMoves.add(new Integer[] {1, 3, 2, 5});
			bExpectedPieceMoves.add(new Integer[] {1, 3, 3, 4});
			bExpectedPieceMoves.add(new Integer[] {1, 3, 0, 5});
							
		//Get Actual
			bActualPieceMoves = Constants.getAllPieceMoves("wn", 1, 3);
		
		//Assert Equal
			MyAsserts.assertArrayArrayListEquals("\n===================   Test the Knight @ d2 moves.   ===================\n", bExpectedPieceMoves, bActualPieceMoves);
	}

	@Test
	//Test the Bishop @ c1 moves
	public final void testGetAllPieceMovesBishopC1() {
		ArrayList<Integer[]> bActualPieceMoves;
	
		//Prepare Expected
			bExpectedPieceMoves.add(new Integer[] {0, 2, 1, 1});
			bExpectedPieceMoves.add(new Integer[] {0, 2, 1, 3});
			
			bExpectedPieceMoves.add(new Integer[] {0, 2, 2, 0});		
			bExpectedPieceMoves.add(new Integer[] {0, 2, 2, 4});
			
			bExpectedPieceMoves.add(new Integer[] {0, 2, 3, 5});
			
			bExpectedPieceMoves.add(new Integer[] {0, 2, 4, 6});
			
			bExpectedPieceMoves.add(new Integer[] {0, 2, 5, 7});
			
		//Get Actual
			bActualPieceMoves = Constants.getAllPieceMoves("wb", 0, 2);
		
		//Assert Equal
			MyAsserts.assertArrayArrayListEquals("\n===================   Test the Bishop @ c1 moves.   ===================\n", bExpectedPieceMoves, bActualPieceMoves);
	}
	
	@Test
	//Test the Bishop @ c3 moves
	public final void testGetAllPieceMovesBishopC3() {
		ArrayList<Integer[]> bActualPieceMoves;
			//Prepare Expected
				bExpectedPieceMoves.add(new Integer[] {2, 2, 0, 4});
				bExpectedPieceMoves.add(new Integer[] {2, 2, 0, 0});
				
				bExpectedPieceMoves.add(new Integer[] {2, 2, 1, 3});
				bExpectedPieceMoves.add(new Integer[] {2, 2, 1, 1});
				
				bExpectedPieceMoves.add(new Integer[] {2, 2, 3, 1});
				bExpectedPieceMoves.add(new Integer[] {2, 2, 3, 3});
				
				bExpectedPieceMoves.add(new Integer[] {2, 2, 4, 0});
				bExpectedPieceMoves.add(new Integer[] {2, 2, 4, 4});
				
				bExpectedPieceMoves.add(new Integer[] {2, 2, 5, 5});
				
				bExpectedPieceMoves.add(new Integer[] {2, 2, 6, 6});
				
				bExpectedPieceMoves.add(new Integer[] {2, 2, 7, 7});
				
			//Get Actual
				bActualPieceMoves = Constants.getAllPieceMoves("wb", 2, 2);
			
			//Assert Equal
				MyAsserts.assertArrayArrayListEquals("\n===================   Test the Bishop @ c3 moves.   ===================\n", bExpectedPieceMoves, bActualPieceMoves);
	}
	
	@Test
	//Test the Bishop @ g5 moves
	public final void testGetAllPieceMovesBishopG5() {
		ArrayList<Integer[]> bActualPieceMoves;
			//Prepare Expected
				bExpectedPieceMoves.add(new Integer[] {4, 6, 0, 2});
				
				bExpectedPieceMoves.add(new Integer[] {4, 6, 1, 3});
				
				bExpectedPieceMoves.add(new Integer[] {4, 6, 2, 4});
				
				bExpectedPieceMoves.add(new Integer[] {4, 6, 3, 7});
				bExpectedPieceMoves.add(new Integer[] {4, 6, 3, 5});
				
				bExpectedPieceMoves.add(new Integer[] {4, 6, 5, 5});
				bExpectedPieceMoves.add(new Integer[] {4, 6, 5, 7});
				
				bExpectedPieceMoves.add(new Integer[] {4, 6, 6, 4});
				
				bExpectedPieceMoves.add(new Integer[] {4, 6, 7, 3});
				
			//Get Actual
				bActualPieceMoves = Constants.getAllPieceMoves("wb", 4, 6);
			
			//Assert Equal
				MyAsserts.assertArrayArrayListEquals("\n===================   Test the Bishop @ g5 moves.   ===================\n", bExpectedPieceMoves, bActualPieceMoves);
	}
	
	@Test
	//Test the Bishop @ c8 moves
	public final void testGetAllPieceMovesBishopC8() {
		ArrayList<Integer[]> bActualPieceMoves;
			//Prepare Expected			
				bExpectedPieceMoves.add(new Integer[] {7, 2, 2, 7});
				
				bExpectedPieceMoves.add(new Integer[] {7, 2, 3, 6});
				
				bExpectedPieceMoves.add(new Integer[] {7, 2, 4, 5});
		
				
				bExpectedPieceMoves.add(new Integer[] {7, 2, 5, 4});
				bExpectedPieceMoves.add(new Integer[] {7, 2, 5, 0});
				
				bExpectedPieceMoves.add(new Integer[] {7, 2, 6, 3});
				bExpectedPieceMoves.add(new Integer[] {7, 2, 6, 1});
				
			//Get Actual
				bActualPieceMoves = Constants.getAllPieceMoves("bb", 7, 2);
			
			//Assert Equal
				MyAsserts.assertArrayArrayListEquals("\n===================   Test the Bishop @ c8 moves.   ===================\n", bExpectedPieceMoves, bActualPieceMoves);
	}
	
	@Test
	//Test the Bishop @ f8 moves
	public final void testGetAllPieceMovesBishopF8() {
		ArrayList<Integer[]> bActualPieceMoves;
			//Prepare Expected
				bExpectedPieceMoves.add(new Integer[] {7, 5, 2, 0});
				
				bExpectedPieceMoves.add(new Integer[] {7, 5, 3, 1});
				
				bExpectedPieceMoves.add(new Integer[] {7, 5, 4, 2});
				
				bExpectedPieceMoves.add(new Integer[] {7, 5, 5, 7});
				bExpectedPieceMoves.add(new Integer[] {7, 5, 5, 3});
				
				bExpectedPieceMoves.add(new Integer[] {7, 5, 6, 6});
				bExpectedPieceMoves.add(new Integer[] {7, 5, 6, 4});
				
			//Get Actual
				bActualPieceMoves = Constants.getAllPieceMoves("bb", 7, 5);
			
			//Assert Equal
				MyAsserts.assertArrayArrayListEquals("\n===================   Test the Bishop @ f8 moves.   ===================\n", bExpectedPieceMoves, bActualPieceMoves);
	}
	
	@Test
	//Test the Queen @ g5 moves
	public final void testGetAllPieceMovesQueenG5() {
		ArrayList<Integer[]> bActualPieceMoves;
			//Prepare Expected
				//Lines
					bExpectedPieceMoves.add(new Integer[] {4, 6, 4, 0});
					bExpectedPieceMoves.add(new Integer[] {4, 6, 0, 6});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 4, 1});
					bExpectedPieceMoves.add(new Integer[] {4, 6, 1, 6});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 4, 2});
					bExpectedPieceMoves.add(new Integer[] {4, 6, 2, 6});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 4, 3});
					bExpectedPieceMoves.add(new Integer[] {4, 6, 3, 6});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 4, 4});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 5, 6});
					bExpectedPieceMoves.add(new Integer[] {4, 6, 4, 5});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 6, 6});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 4, 7});
					bExpectedPieceMoves.add(new Integer[] {4, 6, 7, 6});
					
				//Diagonals
					bExpectedPieceMoves.add(new Integer[] {4, 6, 0, 2});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 1, 3});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 2, 4});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 3, 7});
					bExpectedPieceMoves.add(new Integer[] {4, 6, 3, 5});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 5, 5});
					bExpectedPieceMoves.add(new Integer[] {4, 6, 5, 7});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 6, 4});
					
					bExpectedPieceMoves.add(new Integer[] {4, 6, 7, 3});
				
			//Get Actual
				bActualPieceMoves = Constants.getAllPieceMoves("wq", 4, 6);
			
			//Assert Equal
				MyAsserts.assertArrayArrayListEquals("\n===================   Test the Queen @ g5 moves.   ===================\n", bExpectedPieceMoves, bActualPieceMoves);
	}
	
	@Test
	//Test the King @ g5 moves
	public final void testGetAllPieceMovesKingG5() {
		ArrayList<Integer[]> bActualPieceMoves;
			//Prepare Expected
				bExpectedPieceMoves.add(new Integer[] {4, 6, 3, 5});
				bExpectedPieceMoves.add(new Integer[] {4, 6, 3, 6});
				bExpectedPieceMoves.add(new Integer[] {4, 6, 3, 7});
				
				bExpectedPieceMoves.add(new Integer[] {4, 6, 4, 5});
				bExpectedPieceMoves.add(new Integer[] {4, 6, 4, 7});
				
				bExpectedPieceMoves.add(new Integer[] {4, 6, 5, 5});
				bExpectedPieceMoves.add(new Integer[] {4, 6, 5, 6});
				bExpectedPieceMoves.add(new Integer[] {4, 6, 5, 7});
				
			//Get Actual
				bActualPieceMoves = Constants.getAllPieceMoves("wk", 4, 6);
			
			//Assert Equal
				MyAsserts.assertArrayArrayListEquals("\n===================   Test the King @ g5 moves.   ===================\n", bExpectedPieceMoves, bActualPieceMoves);
	}
	
	@Test
	//Test the Pawn @ d7 moves
	public final void testGetAllPieceMovesPawnD7() {
		ArrayList<Integer[]> bActualPieceMoves;
			//Prepare Expected
				bExpectedPieceMoves.add(new Integer[] {6, 3, 5, 3});
				bExpectedPieceMoves.add(new Integer[] {6, 3, 5, 4});
				bExpectedPieceMoves.add(new Integer[] {6, 3, 5, 2});
				bExpectedPieceMoves.add(new Integer[] {6, 3, 4, 3});
				
			//Get Actual
				bActualPieceMoves = Constants.getAllPieceMoves("bp", 6, 3);
			
			//Assert Equal
				MyAsserts.assertArrayArrayListEquals("\n===================   Test the Pawn @ d7 moves.   ===================\n", bExpectedPieceMoves, bActualPieceMoves);
	}
}
